﻿using Dapper;
using OMG.Fill.Frunit.Model;
using OMG.Fill.Frunit.Model.Ent;
using OMG.Fill.Frunit.Services;
using ProjectShare;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
namespace OMG.Fill.Frunit.Service
{
    /// <summary>
    /// 表5生产经营实体表T_FruProsecution通用操作类
    /// </summary>
    public class FruProsecutions
    {
        /// <summary>
        /// 添加
        /// </summary>
        public virtual ResResult<int> AddInfo(FruProsecutionEntity model) {
            ResResult<int> obj = new ResResult<int>();
            string strSql = @"INSERT INTO dbo.T_FruProsecution";
            strSql += "(";
            strSql += "Id,";
            strSql += "ReportId,";
            strSql += "marketNum,";
            strSql += "cdxMarket,";
            strSql += "zypfMarket,";
            strSql += "qyxzhpfMarket,";
            strSql += "FruCompanyNum,";
            strSql += "zzNum_country,";
            strSql += "zzNum_pro,";
            strSql += "zzNum_city,";
            strSql += "zzNum_county,";
            strSql += "zzNum_other,";
            strSql += "zzNum_singel,";
            strSql += "zzNum_yye1,";
            strSql += "zzNum_yye2,";
            strSql += "zzNum_yye3,";
            strSql += "zzNum_yye4,";
            strSql += "zzNum_yye5,";
            strSql += "zzNum_yye6,";
            strSql += "SgjgNum,";
            strSql += "SgyxNum,";
            strSql += "SgwmNum,";
            strSql += "nmzyhzNum,";
            strSql += "sgzzNhNum,";
            strSql += "ZZDHNum,";
            strSql += "ZZDHOne,";
            strSql += "ZZDHTwo,";
            strSql += "ZZDHThree,";
            strSql += "ymjdNum,";
            strSql += "ymNum,";
            strSql += "DzswNum,";
            strSql += "HzNum,";
            strSql += "zyhzNum,";
            strSql += "nhhzNum,";
            strSql += "hzlzArea,";
            strSql += "nmhzYincome,";
            strSql += "jtncNum,";
            strSql += "jtncnhNum,";
            strSql += "jtncjyArea,";
            strSql += "jtnclzArea,";
            strSql += "jtncYincome,";
            strSql += "zlrzNum_sfx,";
            strSql += "zlrzNum_sfq,";
            strSql += "zgcmsbNum,";
            strSql += "zgmpcpNum,";
            strSql += "ynszmsbNum,";
            strSql += "zlrzNum_sbs,";
            strSql += "zlrzNum_bamj,";
            strSql += "zlrzNum_rzmj,";
            strSql += "zlrzNum_rzsl,";
            strSql += "zlrzNum_wghmj,";
            strSql += "zlrzNum_bluecp,";
            strSql += "zlrzNum_bluecpmj,";
            strSql += "zlrzNum_dlsb,";
            strSql += "zlrzNum_dlbh,";
            strSql += "zlrzNum_wghNum,";
            strSql += "AddUser,";
            strSql += "AddTime,";
            strSql += "UpdateUser,";
            strSql += "UpdateTime)";
            strSql += " values(";
            strSql += "@Id,";
            strSql += "@ReportId,";
            strSql += "@marketNum,";
            strSql += "@cdxMarket,";
            strSql += "@zypfMarket,";
            strSql += "@qyxzhpfMarket,";
            strSql += "@FruCompanyNum,";
            strSql += "@zzNum_country,";
            strSql += "@zzNum_pro,";
            strSql += "@zzNum_city,";
            strSql += "@zzNum_county,";
            strSql += "@zzNum_other,";
            strSql += "@zzNum_singel,";
            strSql += "@zzNum_yye1,";
            strSql += "@zzNum_yye2,";
            strSql += "@zzNum_yye3,";
            strSql += "@zzNum_yye4,";
            strSql += "@zzNum_yye5,";
            strSql += "@zzNum_yye6,";
            strSql += "@SgjgNum,";
            strSql += "@SgyxNum,";
            strSql += "@SgwmNum,";
            strSql += "@nmzyhzNum,";
            strSql += "@sgzzNhNum,";
            strSql += "@ZZDHNum,";
            strSql += "@ZZDHOne,";
            strSql += "@ZZDHTwo,";
            strSql += "@ZZDHThree,";
            strSql += "@ymjdNum,";
            strSql += "@ymNum,";
            strSql += "@DzswNum,";
            strSql += "@HzNum,";
            strSql += "@zyhzNum,";
            strSql += "@nhhzNum,";
            strSql += "@hzlzArea,";
            strSql += "@nmhzYincome,";
            strSql += "@jtncNum,";
            strSql += "@jtncnhNum,";
            strSql += "@jtncjyArea,";
            strSql += "@jtnclzArea,";
            strSql += "@jtncYincome,";
            strSql += "@zlrzNum_sfx,";
            strSql += "@zlrzNum_sfq,";
            strSql += "@zgcmsbNum,";
            strSql += "@zgmpcpNum,";
            strSql += "@ynszmsbNum,";
            strSql += "@zlrzNum_sbs,";
            strSql += "@zlrzNum_bamj,";
            strSql += "@zlrzNum_rzmj,";
            strSql += "@zlrzNum_rzsl,";
            strSql += "@zlrzNum_wghmj,";
            strSql += "@zlrzNum_bluecp,";
            strSql += "@zlrzNum_bluecpmj,";
            strSql += "@zlrzNum_dlsb,";
            strSql += "@zlrzNum_dlbh,";
            strSql += "@zlrzNum_wghNum,";
            strSql += "@AddUser,";
            strSql += "@AddTime,";
            strSql += "@UpdateUser,";
            strSql += "@UpdateTime)";
            try
            {
                using (var dbCon = ConnectFactory.GetOpenConnection())
                {
                    model.Id= CustomFun.GetGuid();
                    int result = dbCon.Execute(strSql, model);
                    if (result > 0)
                    {
                        //ReportServices reportServices = new ReportServices();
                        //reportServices.UpStatus(model.ReportId, "1", "");
                        obj.model = result;
                        obj.status = DefaultKey.SuccessResult;
                        obj.message = "添加成功！";
                    }
                    else
                    {
                        obj.model = result;
                        obj.status = DefaultKey.InfoResult;
                        obj.message = "添加失败！数量为:" + result;
                    }
                    dbCon.Dispose();//数据库连接释放
                    return obj;
                }
            }
            catch (Exception ex)
            {
                obj.status = DefaultKey.ErrorResult;
                obj.message = ex.ToString().Trim();
                LogHelper.ErrorLog("新增表5生产经营实体表T_FruProsecution对象信息失败", ex);
                return obj;
            }
        }
        /// <summary>
        /// 修改
        /// </summary>
        public virtual ResResult<int> UpdateInfo(FruProsecutionEntity model)
        {
            ResResult<int> obj = new ResResult<int>();
            string strSql = @"UPDATE dbo.T_FruProsecution set ";
            strSql += "ReportId = @ReportId,";
            strSql += "marketNum = @MarketNum,";
            strSql += "cdxMarket = @CdxMarket ,";
            strSql += "zypfMarket = @ZypfMarket ,";
            strSql += "qyxzhpfMarket = @QyxzhpfMarket ,";
            strSql += "FruCompanyNum = @FruCompanyNum,";
            strSql += "zzNum_country = @zzNum_country,";
            strSql += "zzNum_pro = @ZzNum_pro,";
            strSql += "zzNum_city = @ZzNum_city,";
            strSql += "zzNum_county = @zzNum_county,";
            strSql += "zzNum_other = @zzNum_other,";
            strSql += "zzNum_singel = @ZzNum_singel,";
            strSql += "zzNum_yye1 = @ZzNum_yye1,";
            strSql += "zzNum_yye2 = @ZzNum_yye2,";
            strSql += "zzNum_yye3 = @ZzNum_yye3,";
            strSql += "zzNum_yye4 = @ZzNum_yye4,";
            strSql += "zzNum_yye5 = @ZzNum_yye5,";
            strSql += "zzNum_yye6 = @ZzNum_yye6,";
            strSql += "SgjgNum = @SgjgNum,";
            strSql += "SgyxNum = @SgyxNum,";
            strSql += "SgwmNum = @SgwmNum,";
            strSql += "nmzyhzNum = @NmzyhzNum,";
            strSql += "hzlzArea = @HzlzArea,";
            strSql += "nmhzYincome = @NmhzYincome ,";
            strSql += "jtncNum = @JtncNum ,";
            strSql += "jtncnhNum = @JtncnhNum ,";
            strSql += "jtncjyArea = @JtncjyArea ,";
            strSql += "jtnclzArea = @JtnclzArea ,";
            strSql += "JtncYincome = @JtncYincome ,";
            strSql += "sgzzNhNum = @SgzzNhNum,";
            strSql += "ZZDHNum = @ZZDHNum,";
            strSql += "ZZDHOne = @ZZDHOne,";
            strSql += "ZZDHTwo = @ZZDHTwo,";
            strSql += "ZZDHThree = @ZZDHThree,";
            strSql += "ymjdNum = @YmjdNum,";
            strSql += "ymNum = @YmNum,";
            strSql += "DzswNum = @DzswNum,";
            strSql += "HzNum = @HzNum,";
            strSql += "zyhzNum = @ZyhzNum,";
            strSql += "nhhzNum = @NhhzNum,";
            strSql += "zlrzNum_sfx = @ZlrzNum_sfx,";
            strSql += "zlrzNum_sfq = @ZlrzNum_sfq,";
            strSql += "ZgcmsbNum = @ZgcmsbNum ,";
            strSql += "ZgmpcpNum = @ZgmpcpNum ,";
            strSql += "YnszmsbNum = @YnszmsbNum ,";
            strSql += "zlrzNum_sbs = @ZlrzNum_sbs,";
            strSql += "zlrzNum_bamj = @ZlrzNum_bamj,";
            strSql += "zlrzNum_rzmj = @ZlrzNum_rzmj,";
            strSql += "zlrzNum_rzsl = @ZlrzNum_rzsl,";
            strSql += "zlrzNum_wghmj = @ZlrzNum_wghmj,";
            strSql += "zlrzNum_bluecp = @ZlrzNum_bluecp,";
            strSql += "zlrzNum_bluecpmj = @ZlrzNum_bluecpmj,";
            strSql += "zlrzNum_dlsb = @ZlrzNum_dlsb,";
            strSql += "zlrzNum_dlbh = @ZlrzNum_dlbh,";
            strSql += "zlrzNum_wghNum = @ZlrzNum_wghNum,";
            strSql += "AddUser = @AddUser,";
            strSql += "AddTime = @AddTime,";
            strSql += "UpdateUser = @UpdateUser,";
            strSql += "UpdateTime = @UpdateTime";
            strSql += " where ReportId = @ReportId";
            try
            {
                using (var dbCon = ConnectFactory.GetOpenConnection())
                {
                    int result = dbCon.Execute(strSql, model);
                    if (result > 0)
                    {
                        ReportServices reportServices = new ReportServices();
                        reportServices.UpStatus(model.ReportId, "2", "");
                        obj.model = result;
                        obj.status = DefaultKey.SuccessResult;
                        obj.message = "更新成功！";
                    }
                    else
                    {
                        obj.model = result;
                        obj.status = DefaultKey.InfoResult;
                        obj.message = "更新失败！数量为:" + result;
                    }
                    dbCon.Dispose();//数据库连接释放
                    return obj;
                }
            }
            catch (Exception ex)
            {
                obj.status = DefaultKey.ErrorResult;
                obj.message = ex.ToString().Trim();
                LogHelper.ErrorLog("更新表5生产经营实体表T_FruProsecution对象信息失败", ex);
                return obj;
            }
        }
        /// <summary>
        /// 删除
        /// </summary>
        public virtual ResResult<int> DeleteInfo(string id)
        {
            ResResult<int> obj = new ResResult<int>();
            string strSql = @"delete from dbo.T_FruProsecution where Id = @Id";
            int result;
            try
            {
                using (var dbCon = ConnectFactory.GetOpenConnection())
                {
                    result = dbCon.Execute(strSql, new { Id = id });
                    if (result > 0)
                    {
                        obj.model = result;
                        obj.status = DefaultKey.SuccessResult;
                        obj.message = "删除成功！";
                    }
                    else
                    {
                        obj.model = result;
                        obj.status = DefaultKey.InfoResult;
                        obj.message = "删除失败！数量为:" + result;
                    }
                    dbCon.Dispose();//数据库连接释放
                    return obj;
                }
            }
            catch (Exception ex)
            {
                obj.status = DefaultKey.ErrorResult;
                obj.message = ex.ToString().Trim();
                LogHelper.ErrorLog("删除表5生产经营实体表T_FruProsecution对象信息失败", ex);
                return obj;
            }
        }
        /// <summary>
        /// 批量删除
        /// </summary>
        public virtual ResResult<int> DeleteBatch(string[] ids)
        {
            ResResult<int> obj = new ResResult<int>();
            string strIds = string.Join(",", ids.Select(x => x.ToString()).ToArray());
            string strSql = @"delete from dbo.T_FruProsecution where Id in @ids";
            var dynamicSqlParam = new DynamicParameters();
            dynamicSqlParam.Add("ids", ids.ToArray(), null, null, null);
            int result;
            try
            {
                using (var dbCon = ConnectFactory.GetOpenConnection())
                {
                    result = dbCon.Execute(strSql, dynamicSqlParam);
                    if (result > 0)
                    {
                        obj.model = result;
                        obj.status = DefaultKey.SuccessResult;
                        obj.message = "删除成功！";
                    }
                    else
                    {
                        obj.status = DefaultKey.InfoResult;
                        obj.message = "删除失败！数量为:" + result;
                    }
                    dbCon.Dispose();//数据库连接释放
                    return obj;
                }
            }
            catch (Exception ex)
            {
                LogHelper.ErrorLog("获取数据字典表批量删除表5生产经营实体表T_FruProsecution表失败", ex);
                obj.message = ex.ToString().Trim();
                obj.status = DefaultKey.ErrorResult;
                return obj;
            }
        }
        /// <summary>
        /// 获取指定对象
        /// </summary>
        public virtual ResResult<FruProsecutionEntity> GetModel(string id) {
            ResResult<FruProsecutionEntity> obj = new ResResult<FruProsecutionEntity>();
            string strSql = @"select * from dbo.T_FruProsecution where Id = @Id";
            try
            {
                using (var dbCon = ConnectFactory.GetOpenConnection())
                {
                    obj.model = dbCon.Query<FruProsecutionEntity>(strSql, new { Id = id }).FirstOrDefault();
                    obj.status = DefaultKey.SuccessResult;
                    obj.message = "获取成功！";
                    dbCon.Dispose();//数据库连接释放
                    return obj;
                }
            }
            catch (Exception ex)
            {
                obj.status = DefaultKey.ErrorResult;
                obj.message = ex.ToString().Trim();
                LogHelper.ErrorLog("获取表5生产经营实体表T_FruProsecution对象信息失败", ex);
                return obj;
            }
        }
        /// <summary>
        /// 获取今往年数据
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ResResult<FruProsecutionViewModel> GetModel(VegNowModel model)
        {
            ResResult<FruProsecutionViewModel> obj = new ResResult<FruProsecutionViewModel>();
            FruProsecutionEntity Entity = new FruProsecutionEntity();
            FruProsecutionViewModel viewModel = new FruProsecutionViewModel();
            DictServices dictServices = new DictServices();
            var paramlist = new DynamicParameters();
            string strSqlReport = "";
            if (model != null)
            {
                if (!string.IsNullOrEmpty(model.AreaCode) && !string.IsNullOrEmpty(model.ReportCode) && !string.IsNullOrEmpty(model.FillInYear))
                {
                    string FillInYear = dictServices.GetKey(model.FillInYear);
                    paramlist.Add("AreaCode", model.AreaCode);
                    paramlist.Add("ReportCode", model.ReportCode);
                    paramlist.Add("FillInYear", FillInYear);
                    int OldFillInYear = Convert.ToInt32(FillInYear) - 1;
                    if (OldFillInYear < 0)
                    {
                        OldFillInYear = 0;
                    }
                    paramlist.Add("OldFillInYear", OldFillInYear.ToString());
                    string strNowSql = "select FP.Id,FP.ReportId,FruCompanyNum,zzNum_pro,zzNum_city,zzNum_singel,zzNum_yye1,zzNum_yye2,zzNum_yye3";
                    strNowSql += ", zzNum_yye4, zzNum_yye5, zzNum_yye6, SgjgNum, SgyxNum, SgwmNum, nmzyhzNum, sgzzNhNum, ZZDHNum, ZZDHOne, ZZDHTwo, ZZDHThree";
                    strNowSql += ", ymjdNum, ymNum, DzswNum, HzNum, zyhzNum, nhhzNum,hzlzArea, zlrzNum_sfx, zlrzNum_sfq, zlrzNum_sbs, zlrzNum_bamj, zlrzNum_rzmj, zlrzNum_rzsl, zlrzNum_wghmj";
                    strNowSql += ", marketNum,cdxMarket,zypfMarket,qyxzhpfMarket,jtncNum,jtncnhNum,jtncjyArea,jtnclzArea,jtncYincome,zzNum_other,nmhzYincome,zzNum_country,zzNum_county,zgcmsbNum,zgmpcpNum,ynszmsbNum";
                    strNowSql += ", zlrzNum_bluecp, zlrzNum_bluecpmj, zlrzNum_dlsb, zlrzNum_dlbh, zlrzNum_wghNum ,FP.AddUser,FP.AddTime,FP.UpdateUser,FP.UpdateTime,ReportCode,Opinion,Status as ReportStatus   from T_Report r left join [dbo].[T_FruProsecution] FP on r.id = Fp.ReportId WHERE ReportCode = @ReportCode and FillInYear = @FillInYear and AreaCode = @AreaCode ";
                    string strOldSql = "select FP.Id as OldId,FP.ReportId as OldReportId,FruCompanyNum as OldFruCompanyNum,zzNum_pro as OldzzNum_pro,zzNum_city as OldzzNum_city,zzNum_singel as OldzzNum_singel,zzNum_yye1 as OldzzNum_yye1,zzNum_yye2 as OldzzNum_yye2,zzNum_yye3 OldzzNum_yye3";
                    strOldSql += ", zzNum_yye4 OldzzNum_yye4, zzNum_yye5 OldzzNum_yye5, zzNum_yye6 OldzzNum_yye6, SgjgNum OldSgjgNum, SgyxNum OldSgyxNum, SgwmNum as OldSgwmNum, nmzyhzNum as OldnmzyhzNum, sgzzNhNum as OldsgzzNhNum,hzlzArea as OldhzlzArea, ZZDHNum as OldZZDHNum, ZZDHOne as OldZZDHOne, ZZDHTwo as OldZZDHTwo, ZZDHThree as OldZZDHThree";
                    strOldSql += ", marketNum as OldmarketNum,cdxMarket as OldcdxMarket,zypfMarket as OldzypfMarket,qyxzhpfMarket as OldqyxzhpfMarket,jtncNum as OldjtncNum,jtncnhNum as OldjtncnhNum,jtncjyArea as OldjtncjyArea,jtnclzArea as OldjtnclzArea,jtncYincome as OldjtncYincome,zzNum_other as OldzzNum_other,nmhzYincome as OldnmhzYincome,zzNum_country OldzzNum_country,zzNum_county OldzzNum_county,zgcmsbNum OldzgcmsbNum,zgmpcpNum OldzgmpcpNum,ynszmsbNum OldynszmsbNum";
                    strOldSql += ", ymjdNum OldymjdNum, ymNum OldymNum, DzswNum as OldDzswNum, HzNum OldHzNum, zyhzNum OldzyhzNum, nhhzNum OldnhhzNum, zlrzNum_sfx OldzlrzNum_sfx, zlrzNum_sfq OldzlrzNum_sfq, zlrzNum_sbs OldzlrzNum_sbs, zlrzNum_bamj OldzlrzNum_bamj, zlrzNum_rzmj OldzlrzNum_rzmj, zlrzNum_rzsl OldzlrzNum_rzsl, zlrzNum_wghmj OldzlrzNum_wghmj";
                    strOldSql += ", zlrzNum_bluecp OldzlrzNum_bluecp, zlrzNum_bluecpmj OldzlrzNum_bluecpmj, zlrzNum_dlsb OldzlrzNum_dlsb, zlrzNum_dlbh OldzlrzNum_dlbh, zlrzNum_wghNum OldzlrzNum_wghNum   ";
                    strOldSql += ",FP.AddUser as OldAddUser,FP.AddTime as OldAddTime,FP.UpdateUser as OldUpdateUser,FP.UpdateTime as OldUpdateTime,ReportCode,Status as OldReportStatus from T_Report r left join [dbo].[T_FruProsecution] FP on r.id = Fp.ReportId where ReportCode = @ReportCode and FillInYear = @OldFillInYear and AreaCode = @AreaCode ";

                    strSqlReport = "SELECT * FROM ((" + strNowSql + ")t LEFT JOIN  (" + strOldSql + ")tt ON t.ReportId = tt.ReportCode)";

                    //判断选择的年度与上一年度是否生成过报表
                    if (CheckRepCreate(model.ReportCode, model.AreaCode, FillInYear) && CheckRepCreate(model.ReportCode, model.AreaCode, OldFillInYear.ToString()))
                    {
                        obj.model = viewModel;
                        obj.status = -1;
                        obj.message = model.FillInYear + "与上一年的报表没有填报数据！！";
                        return obj;
                    }
                    //判断本年是否生成过报表
                    else if (CheckRepCreate(model.ReportCode, model.AreaCode, FillInYear))
                    {
                        var dbCon = ConnectFactory.GetOpenConnection();
                        obj.model = dbCon.Query<FruProsecutionViewModel>(strOldSql, paramlist).FirstOrDefault();
                        obj.status = -2;
                        obj.message = model.FillInYear + "的报表没有填报数据！！";
                        dbCon.Dispose();//数据库连接释放
                        return obj;
                    }
                    else
                    {
                        //获取报表Id
                        Entity.ReportId = GetReportId(model.ReportCode, model.AreaCode, FillInYear);
                        //判断表T_VegFacility是否初始化过
                        if (CheckRepCount(Entity.ReportId))
                        {
                            if (AddInfo(Entity).status > 0)//报表初始化
                            {
                                using (var dbCon = ConnectFactory.GetOpenConnection())
                                {
                                    //查询去年数据
                                    obj.model = dbCon.Query<FruProsecutionViewModel>(strSqlReport, paramlist).FirstOrDefault();
                                    obj.status = 1;//初始化成功status为1
                                    obj.message = "T_VegProsecution报表初始化成功！";
                                    dbCon.Dispose();//数据库连接释放
                                }
                            }
                        }
                        else
                        {
                            try
                            {
                                using (var dbCon = ConnectFactory.GetOpenConnection())
                                {
                                    obj.model = dbCon.Query<FruProsecutionViewModel>(strSqlReport, paramlist).FirstOrDefault();
                                    obj.status = 2;//成功状态为2
                                    obj.message = "获取T_VegProsecution报表今往年数据成功！";
                                    dbCon.Dispose();//数据库连接释放
                                }
                            }
                            catch (Exception ex)
                            {
                                obj.status = 0; //失败状态
                                obj.message = ex.ToString().Trim();
                                LogHelper.ErrorLog("获取T_VegProsecution报表今往年数据失败", ex);
                            }
                        }
                    }
                }
            }
            return obj;
        }
        /// <summary>
        /// 判定是否生成过报表
        /// </summary>
        /// <param name="reportId"></param>
        /// <returns>没生成过true,否则false</returns>
        public bool CheckRepCount(string reportId)
        {
            string strSql = @"select count(1) from dbo.T_FruProsecution where ReportId=@ReportId";
            try
            {
                using (var dbCon = ConnectFactory.GetOpenConnection())
                {
                    //为0，没生成过true,否则false
                    return dbCon.Query<int>(strSql, new { ReportId = reportId }).FirstOrDefault() == 0 ? true : false;
                }
            }
            catch (Exception ex)
            {
                LogHelper.ErrorLog("更新表1蔬菜生产实体情况表T_FruProsecution对象信息失败", ex);
                return false;
            }
        }

        /// <summary>
        /// 根据地区、报表代码、填报年度判断是否生成过报表
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool CheckRepCreate(string ReportCode, string AreaCode, string FillInYear)
        {
            string strSql = @"select count(1) from dbo.T_Report where ReportCode = @ReportCode and AreaCode = @AreaCode and FillInYear = @FillInYear ";
            try
            {
                using (var dbCon = ConnectFactory.GetOpenConnection())
                {
                    //为0，没生成过true,否则false
                    return dbCon.Query<int>(strSql, new { ReportCode = ReportCode, AreaCode = AreaCode, FillInYear = FillInYear }).FirstOrDefault() == 0 ? true : false;
                }
            }
            catch (Exception ex)
            {
                LogHelper.ErrorLog("当前填报年度的表T_FruProsecution没有生成过", ex);
                return false;
            }
        }


        /// <summary>
        /// 根据地区、报表代码、填报年度获取报表Id
        /// </summary>
        /// <param name="ReportCode"></param>
        /// <param name="AreaCode"></param>
        /// <param name="FillInYear"></param>
        /// <returns></returns>
        public string GetReportId(string ReportCode, string AreaCode, string FillInYear)
        {
            string strSql = @"select * from dbo.T_Report where ReportCode = @ReportCode and AreaCode = @AreaCode and FillInYear = @FillInYear ";
            try
            {
                using (var dbCon = ConnectFactory.GetOpenConnection())
                {
                    return dbCon.Query<ReportEntity>(strSql, new { ReportCode = ReportCode, AreaCode = AreaCode, FillInYear = FillInYear }).FirstOrDefault().Id;
                }
            }
            catch (Exception ex)
            {
                LogHelper.ErrorLog("当前填报年度的表T_FruProsecution没有生成过", ex);
                return "0";
            }
        }
        /// <summary>
        /// 获取全部列表
        /// </summary>
        /// <returns></returns>
        public virtual ResResult<List<FruProsecutionEntity>> GetList()
        {
            ResResult<List<FruProsecutionEntity>> obj = new ResResult<List<FruProsecutionEntity>>();
            string strSql = @"select * from dbo.T_FruProsecution";
            try
            {
                using (var dbCon = ConnectFactory.GetOpenConnection())
                {
                    obj.model = dbCon.Query<FruProsecutionEntity>(strSql).ToList();
                    obj.status = DefaultKey.SuccessResult;
                    obj.message = "获取成功！";
                    dbCon.Dispose();//数据库连接释放
                    return obj;
                }
            }
            catch (Exception ex)
            {
                obj.status = DefaultKey.ErrorResult;
                obj.message = ex.ToString().Trim();
                LogHelper.ErrorLog("更新表5生产经营实体表T_FruProsecution对象信息失败", ex);
                return obj;
            }
        }
    }
}